package com.meshnetics.gb.type.impl.additional;

import com.meshnetics.gb.type.DataValue;

import java.nio.ByteBuffer;

/**
 * Type of enumeration.
 *
 * @author Yury Aserchev (yaserchev@meshnetics.com)
 *         Date: 26.08.2008 12:41:48
 */
public final class TypeEnumeration extends BaseDataType {
    private final Class enumClass;

    public TypeEnumeration(final String name, final Class enumClass) {
        super(name);
        if (enumClass == null) {
            throw new NullPointerException("parameter enumClass is null");
        }
        if (!Enumeration.class.isAssignableFrom(enumClass)) {
            throw new IllegalArgumentException("expected child class of Enumeration, but passed: " +
                    enumClass.getName());
        }
        this.enumClass = enumClass;
    }

    public DataValue deserialize(final ByteBuffer buffer) {
        return Enumeration.valueOf(enumClass, buffer);
    }
}
